<template>
	<div class="hy-container">
		<HyPageHeader :title="heTitle.title" :buttonData="buttonData">
			<div class="content">
				<!--单位信息-->
				<HyCard :title="hyCard1.title">
					<!-- <el-button @click="logList">打印</el-button> -->
					<HyFormCopy ref="hyFormRefRespons1" :hyFormDefault="searchDefault1" :hyFormConfig="searchConfig" :hyFormFields="searchFields1"></HyFormCopy>
				</HyCard>
				<!--设计单位信息-->
				<HyCard :title="hyCard2.title" class="HyCard">
					<HyFormCopy ref="hyFormRefRespons2" :hyFormDefault="searchDefault2" :hyFormConfig="searchConfig" :hyFormFields="searchFields2"></HyFormCopy>
				</HyCard>
				<!--数字化应用信息-->
				<HyCard :title="hyCard3.title" class="HyCard">
					<HyFormCopy ref="hyFormRefRespons3" :hyFormDefault="searchDefault3" :hyFormConfig="searchConfig" :hyFormFields="searchFields3"></HyFormCopy>
					<div class="TableForm">
						<span>应用总预算明细</span>
						<BudgetDetailsTable ref="TableFormData" :table-data="tableData" @table-summaries="tableSummaries"></BudgetDetailsTable>
					</div>
					<!-- <el-button @click="logList">打印</el-button> -->
				</HyCard>
				<!--网络资源信息-->
				<HyCard :title="hyCard4.title" class="HyCard">
					<HyFormCopy ref="hyFormRefRespons4" :hyFormDefault="searchDefault4" :hyFormConfig="searchConfig" :hyFormFields="searchFields4"></HyFormCopy>
				</HyCard>
				<!--部门专网-->
				<div v-show="netResource3">
					<HyCard :title="hyCard5.title" :tooltip="hyCard5.tooltip" class="HyCard">
						<HyFormCopy
							ref="hyFormRefRespons5"
							:hyFormDefault="searchDefault6"
							:hyFormConfig="searchConfig"
							:hyFormFields="searchFields5"
						></HyFormCopy>
						<!--上传-->
						<div class="uploadDiv">
							<span class="span-require">* </span>
							<span>佐证材料（上传佐证材料）： </span>
							<el-upload
								v-model:file-list="decCardList1"
								class="upload-demo"
								:action="baseURL + '/admin/sys-file/upload'"
								multiple
								:before-upload="(file) => beforeUpload(file, fileList(2).accept)"
								:accept="fileList(2).accept"
								:headers="headers"
							>
								<el-button type="primary" icon="Upload">上传附件</el-button>
								<template #tip>
									<div class="el-upload__tip"><span class="span-require">*</span>{{ fileList(2).tips }}</div>
								</template>
							</el-upload>
						</div>
					</HyCard>
				</div>
				<!--部门专线-->
				<div v-show="netResource4">
					<HyCard :title="hyCard6.title" :tooltip="hyCard6.tooltip" class="HyCard">
						<HyFormCopy
							ref="hyFormRefRespons6"
							:hyFormDefault="searchDefault5"
							:hyFormConfig="searchConfig"
							:hyFormFields="searchFields6"
						></HyFormCopy>
						<!--上传-->
						<div class="uploadDiv">
							<span class="span-require">* </span>
							<span>佐证材料（上传佐证材料）： </span>
							<el-upload
								v-model:file-list="decCardList2"
								class="upload-demo"
								:action="baseURL + '/admin/sys-file/upload'"
								multiple
								:before-upload="(file) => beforeUpload(file, fileList(2).accept)"
								:accept="fileList(2).accept"
								:headers="headers"
							>
								<el-button type="primary" icon="Upload">上传附件</el-button>
								<template #tip>
									<div class="el-upload__tip"><span class="span-require">*</span>{{ fileList(2).tips }}</div>
								</template>
							</el-upload>
						</div>
					</HyCard>
				</div>
				<!--互联网专线-->
				<div v-show="netResource5">
					<HyCard :title="hyCard7.title" :tooltip="hyCard7.tooltip" class="HyCard">
						<HyFormCopy
							ref="hyFormRefRespons7"
							:hyFormDefault="searchDefault7"
							:hyFormConfig="searchConfig"
							:hyFormFields="searchFields7"
						></HyFormCopy>
						<!--上传-->
						<div class="uploadDiv">
							<span class="span-require">* </span>
							<span>佐证材料（上传佐证材料）： </span>
							<el-upload
								v-model:file-list="decCardList3"
								class="upload-demo"
								:action="baseURL + '/admin/sys-file/upload'"
								multiple
								:before-upload="(file) => beforeUpload(file, fileList(2).accept)"
								:accept="fileList(2).accept"
								:headers="headers"
							>
								<el-button type="primary" icon="Upload">上传附件</el-button>
								<template #tip>
									<div class="el-upload__tip"><span class="span-require">*</span>{{ fileList(2).tips }}</div>
								</template>
							</el-upload>
						</div>
					</HyCard>
				</div>
				<!--电子政务外网部门接入网-->
				<div v-show="netResource6">
					<HyCard :title="hyCard8.title" :tooltip="hyCard8.tooltip" class="HyCard">
						<HyFormCopy
							ref="hyFormRefRespons8"
							:hyFormDefault="searchDefault8"
							:hyFormConfig="searchConfig"
							:hyFormFields="searchFields8"
						></HyFormCopy>
						<!--上传-->
						<div class="uploadDiv">
							<span class="span-require">* </span>
							<span>佐证材料（上传佐证材料）： </span>
							<el-upload
								v-model:file-list="decCardList4"
								class="upload-demo"
								:action="baseURL + '/admin/sys-file/upload'"
								multiple
								:before-upload="(file) => beforeUpload(file, fileList(2).accept)"
								:accept="fileList(2).accept"
								:headers="headers"
							>
								<el-button type="primary" icon="Upload">上传附件</el-button>
								<template #tip>
									<div class="el-upload__tip"><span class="span-require">*</span>{{ fileList(2).tips }}</div>
								</template>
							</el-upload>
						</div>
					</HyCard>
				</div>
				<!--四个上传-->
				<HyCard :title="hyCard9.title" class="HyCard">
					<div class="imglist">
						<div class="listitem">
							<span class="span-require">* </span>
							<span>总体业务架构图:</span
							><TsyUploadFile type="submit" :fileLimit="1" :fileType="fileImgList(0)" :fileSize="200" v-model="imgList.businessImgFiles" />
						</div>
						<div class="listitem">
							<span class="span-require">* </span>
							<span>系统架构图上传:</span
							><TsyUploadFile type="submit" :fileLimit="1" :fileType="fileImgList(0)" :fileSize="200" v-model="imgList.systemImgFiles" />
						</div>
						<div class="listitem">
							<div>
								<span class="span-require">* </span>
								<span>数据流向图上传：</span><el-button link type="primary" @click="downLoadFile('数字化应用数据流向图.pptx')">模板下载</el-button>
							</div>
							<TsyUploadFile type="submit" :fileLimit="1" :fileType="fileImgList(1)" :fileSize="200" v-model="imgList.dataImgFiles" />
						</div>
						<div class="listitem">
							<span class="span-require">* </span>
							<span>网络拓扑图上传:</span
							><TsyUploadFile type="submit" :fileLimit="1" :fileType="fileImgList(0)" :fileSize="200" v-model="imgList.netImgFiles" />
						</div>
					</div>
					<!--模板下载-->
				</HyCard>
				<!--两个上传----业务清单-->
				<HyCard :title="hyCard10.title" class="HyCard">
					<div class="uploadDiv">
						<span class="span-require">* </span>
						<span>业务事项清单： </span><el-button link type="primary" @click="downLoadFile('数字化应用业务事项清单.xlsx')">模板下载</el-button>
						<el-upload
							v-model:file-list="decCardList5"
							class="upload-demo"
							:action="baseURL + '/admin/sys-file/upload'"
							multiple
							:before-upload="(file) => beforeUpload(file, fileList(3).accept)"
							:accept="fileList(3).accept"
							:headers="headers"
						>
							<el-button type="primary" icon="Upload">上传附件</el-button>
							<template #tip>
								<div class="el-upload__tip"><span class="span-require">*</span>{{ fileList(3).tips }}</div>
							</template>
						</el-upload>
					</div>
					<div class="uploadDiv uploadDivNext">
						<span class="span-require">* </span>
						<span>资金计划报告（上传资金计划报告）： </span
						><el-button link type="primary" @click="downLoadFile('数字化应用资金计划报告.docx')">模板下载</el-button>
						<el-upload
							v-model:file-list="decCardList6"
							class="upload-demo"
							:action="baseURL + '/admin/sys-file/upload'"
							multiple
							:before-upload="(file) => beforeUpload(file, fileList(2).accept)"
							:accept="fileList(2).accept"
							:headers="headers"
						>
							<el-button type="primary" icon="Upload">上传附件</el-button>
							<template #tip>
								<div class="el-upload__tip"><span class="span-require">*</span>{{ fileList(2).tips }}</div>
							</template>
						</el-upload>
					</div>
				</HyCard>
				<!--tabs切换-->
				<HyCard :title="hyCard11.title" class="HyCard">
					<el-tabs v-model="activeName" type="card" class="demo-tabs" @tab-click="handleClick">
						<el-tab-pane label="全口径编目" name="first"
							><FirstTab ref="firstTab" :firstTabList="firstTabList" :declareSubmit="isDeclareSubmit"></FirstTab
						></el-tab-pane>
						<el-tab-pane label="数字化应用开发" name="second"><SecondTab ref="secondTab" :secondTabList="secondTabList" /></el-tab-pane>
						<el-tab-pane label="资金测算明细" name="third"
							><BudgetDetailsTable ref="TableFormDataCal" :table-data="tableDataThere" @table-summaries="tableSummariesCal"
						/></el-tab-pane>
					</el-tabs>
				</HyCard>
			</div>
		</HyPageHeader>
		<Start ref="startRef" :boxConfig="{ title: '确认提交申报？', width: '40%' }" @submitPass="submitPass"></Start>
	</div>
</template>

<script lang="ts" setup>
import HyCard from '/@/components/HyCard/index.vue';
import HyPageHeader from '/@/components/HyPageHeader/index.vue';
import HyFormCopy from '/@/components/HyFormCopy/index.vue';
import FirstTab from './components/firstTab.vue';
import SecondTab from './components/secondTab.vue';
import ThereTab from './components/thereTab.vue';
import TableForm from './components/tableForm.vue';
import BudgetDetailsTable from '../../areaDigitalApp/appDeclaration/BudgetDetailsTable.vue';
import other from '/@/utils/other';
import UploadFile from './components/uploadFile.vue';
import { declareSubmit, declareSave, declareByIdAppDe, declareLocalFile } from '/@/api/digitalList/digitalLization';
import { getByIdAppDeclare } from '/@/api/decManagement/detail';
import type { TabsPaneContext } from 'element-plus';
import TsyUploadFile from '/@/components/HyUpload/index.vue';
import { Session } from '/@/utils/storage';
import { ElMessage, ElMessageBox, ElLoading } from 'element-plus';
import { useDict } from '/@/hooks/dict';
import { isNull, formatData, formatTable, formatDataList, beforeUpload, fileList, fileImgList, downLoadFile, declareSaveList } from './hooks/index';
import mittBus from '/@/utils/mitt';
import { Message } from '@element-plus/icons-vue/dist/types';
import { flowName } from '/@/constants';
import Start from '@cqdcg/admin/views/flow/form/tools/startFlow';
//四个上传
const imgList = ref({
	businessImgFiles: [],
	systemImgFiles: [],
	dataImgFiles: [],
	netImgFiles: [],
});
const netResource3 = ref(false); //部门专网
const netResource4 = ref(false); //部门专线
const netResource5 = ref(false); //互联网专线
const netResource6 = ref(false); //电子政务外网部门接入网
const tableData = ref([
	{
		numIdx: '1',
		parentNumIdx: '0',
		name: '网络资源费用',
		amount: null,
		remark: '',
	},
]);
const tableDataThere = ref([
	{
		numIdx: '1',
		parentNumIdx: '0',
		name: '应用建设费用',
		amount: null,
		remark: '',
	},
]);
const buttonData = computed(() => {
	return [
		{ name: '保存', class: 'wihte-button', click: () => submitValueList('save') },
		{ name: '申报', class: 'blue-button', click: () => submitValueList('add') },
	];
});
const isDeclareSubmit = ref(false);
const decCardList1 = ref([]); //部门专网文件
const decCardList2 = ref([]); //部门专线文件
const decCardList3 = ref([]); //互联网专线文件
const decCardList4 = ref([]); //电子政务外网部门接入网文件
const decCardList5 = ref([]); //业务事项清单文件
const decCardList6 = ref([]); //资金计划报告文件
const firstTabList = ref({});
const secondTabList = ref();
const types = {
	'1': decCardList1,
	'2': decCardList2,
	'3': decCardList3,
	'4': decCardList4,
	'5': decCardList5,
	'6': decCardList6,
};
const headers = computed(() => {
	return {
		Authorization: 'Bearer ' + Session.get('token'),
		'TENANT-ID': Session.getTenant(),
	};
});
//数字化应用编码和名称
const editPageAdd = ref(false);
const threeListName = ref('');
const declareId = ref('');
const chooseType = ref(0); //开发：1运维项目：2
const appCode = ref(''); //7bad77ea9c914d79//1874801040464ce8/528c9e79f0014d1e/99033b3799e54407/1234560000123456/6f6fbc0eeb634374
// const appCode = ref('');
const belongDomain = ref('');
const belongDomainName = ref('');
//获取子组件实例
const hyFormRefRespons1 = ref();
const hyFormRefRespons2 = ref();
const hyFormRefRespons3 = ref();
const hyFormRefRespons4 = ref();
const hyFormRefRespons5 = ref();
const hyFormRefRespons6 = ref();
const hyFormRefRespons7 = ref();
const hyFormRefRespons8 = ref();
//上传
// const hyFormRefRespons9 = ref();
// const hyFormRefRespons10 = ref();
//申报时提交的数据汇总
const dataList = ref({});
const TableFormData = ref();
const TableFormDataCal = ref();
const formDataTotalBudget = ref(0); //第一个费用明细total
const formDataTotalCalCulate = ref(0); //第二个费用明细total
const formDataList = ref([]);
const tableSummaries = (param?: any) => {
	formDataTotalBudget.value = param;
};
const tableSummariesCal = (param?: any) => {
	formDataTotalCalCulate.value = param;
};
const logList = () => {
	const arr = ['1'];
	console.log(arr.includes('2'));
};
const confirm = () => {
	const list = [];
	const getFiles = (fileList) => {
		if (fileList && fileList.length) {
			let resArr = [];
			fileList.forEach((item) => {
				resArr.push({
					name: item.name || item.response.data.name,
					url: item.url || item.response.data.url,
					id: item.id || item.response.data.id,
				});
			});
			return resArr;
		} else {
			return [];
		}
	};
	const getListItem = (formRef, type, fileList) => {
		const files = getFiles(fileList);
		return {
			appCode: appCode.value,
			type: type,
			...formRef.value?.hyForm,
			files: files,
		};
	};
	const netResource = hyFormRefRespons4.value.hyForm && hyFormRefRespons4.value.hyForm.netResource;
	if (netResource) {
		if (netResource.includes('3')) {
			list.push(getListItem(hyFormRefRespons5, '3', decCardList1.value));
		}
		if (netResource.includes('4')) {
			list.push(getListItem(hyFormRefRespons6, '4', decCardList2.value));
		}
		if (netResource.includes('5')) {
			list.push(getListItem(hyFormRefRespons7, '5', decCardList3.value));
		}
		if (netResource.includes('6')) {
			list.push(getListItem(hyFormRefRespons8, '6', decCardList4.value));
		}
	}

	let matterArr = getFiles(decCardList5.value);
	let fundReportArr = getFiles(decCardList6.value);

	dataList.value = {
		base: {
			appCode: appCode.value,
			appName: searchDefault3.value.appName,
			...hyFormRefRespons3.value.hyForm,
			developBeginDate: hyFormRefRespons3.value.hyForm.developBeginDateArr && hyFormRefRespons3.value.hyForm.developBeginDateArr[0]?.slice(0, 10),
			developEndDate: hyFormRefRespons3.value.hyForm.developBeginDateArr && hyFormRefRespons3.value.hyForm.developBeginDateArr[1]?.slice(0, 10),
			terminal: hyFormRefRespons3.value.hyForm.terminal && hyFormRefRespons3.value.hyForm.terminal.join(','),
			fundResource: hyFormRefRespons3.value.hyForm.fundResource && hyFormRefRespons3.value.hyForm.fundResource.join(','),
			totalBudget: hyFormRefRespons3.value.hyForm.totalBudget - 0,
			yearBudget: hyFormRefRespons3.value.hyForm.yearBudget - 0,
			...hyFormRefRespons1.value.hyForm,
			...hyFormRefRespons2.value.hyForm,
			centerAmount: hyFormRefRespons3.value.hyForm.centerAmount - 0,
		},
		//网络资源类型
		net: {
			//将...hyFormRefRespons4.value.hyForm转为字符串
			netResource: hyFormRefRespons4.value.hyForm.netResource && hyFormRefRespons4.value.hyForm.netResource.join(','),
			netList: list,
			//四个上传
			businessImg: imgList.value.businessImgFiles && imgList.value.businessImgFiles[0],
			systemImg: imgList.value?.systemImgFiles && imgList.value?.systemImgFiles[0],
			dataImg: imgList.value?.dataImgFiles && imgList.value?.dataImgFiles[0],
			netImg: imgList.value?.netImgFiles && imgList.value?.netImgFiles[0],
			matter: matterArr,
			fundReport: fundReportArr,
		},
		//IRS
	};
	// console.log(dataList.value, '提交的数据');
};
const heTitle = ref({
	title: '数字化应用申报', //顶部
});
const hyCard1 = ref({
	title: '单位信息',
});
const hyCard2 = ref({
	title: '设计单位信息',
});
const hyCard3 = ref({
	title: '数字化应用信息',
});
const hyCard4 = ref({
	title: '网络资源信息',
});
const hyCard5 = ref({
	title: '部门专网',
	tooltip: {
		message: '部门专网',
		position: 'top',
	},
});
const hyCard6 = ref({
	title: '部门专线',
	tooltip: {
		message: '部门专线',
		position: 'top',
	},
});
const hyCard7 = ref({
	title: '互联网专线',
	tooltip: {
		message: '互联网专线',
		position: 'top',
	},
});
const hyCard8 = ref({
	title: '电子政务外网部门接入网',
	tooltip: {
		message: '电子政务外网部门接入网',
		position: 'top',
	},
});
const hyCard9 = ref({
	title: '',
});
const hyCard10 = ref({
	title: '',
});
const hyCard11 = ref({
	title: '',
});
const activeName = ref('first');
//编辑传数据
const searchDefault1 = ref({
	responsibleDept: '',
	budgetUnit: '',
	leadDept: '',
	report: '',
	reportDetail: '',
	liabilityDepartment: '',
	teamLeaderUnitName: '',
});
const searchDefault2 = ref({
	socialCode: '',
	designUnit: '',
});
const searchDefault3 = ref({
	appCode: '',
	appName: '',
	principalName: '',
	principalPhone: 0,
	projectType: '',
	developStatus: '',
	budgetYear: '',
	developBeginDateArr: [],
	domain: '',
	supervise: '',
	paper: '',
	according: '',
	summarize: '',
	terminal: [],
	zfbIssue: null,
	chatIssue: null,
	webIssue: null,
	pcIssue: null,
	totalBudget: 0,
	yearBudget: 0,
	fundResource: [],
	otherFund: '',
	centerAmount: 0,
	cityAmount: 0,
	districtAmount: 0,
	deptAmount: 0,
	bankAmount: 0,
	otherAmount: 0,
});
const searchDefault4 = ref({
	netResource: [],
});
const searchDefault5 = ref({
	according: '',
	budget: 0,
});
const searchDefault6 = ref({
	selfName: '',
	oppositeName: '',
	according: '',
	budget: 0,
});
const searchDefault7 = ref({
	selfName: '',
	according: '',
	budget: 0,
});
const searchDefault8 = ref({
	selfName: '',
	oppositeName: '',
	condition: '',
	budget: 0,
});
const searchDefault = ref({});
const searchConfig = ref({
	span: 6,
	offset: 0,
	type: 'submit',
});
// 配置搜索
//单位信息
const isChangeReport1 = ref('');
const searchFields1 = ref({
	responsibleDept: {
		type: 'input',
		label: '责任部门',
		span: 8,
		required: true,
		disabled: true,
	},
	budgetUnit: {
		type: 'input',
		label: '预算单位',
		placeholder: '请输入预算单位',
		maxlength: 16,
		showWordLimit: true,
		span: 8,
		required: true,
	},
	leadDept: {
		type: 'input',
		label: '应用牵头部门（专题组组长单位）',
		labelWidth: 135,
		span: 8,
		required: true,
		disabled: true,
	},
	report: {
		type: 'select',
		label: '是否需要企业直报数据',
		required: true,
		span: 8,
		options: [],
		change(e) {
			searchFields1.value.reportDetail.type = e == '1' ? 'textarea' : '';
		},
	},
	reportDetail: {
		type: '',
		label: '企业直报数据描述',
		placeholder: '请输入企业直报数据描述',
		maxlength: 500,
		rows: 3,
		span: 24,
		required: true,
	},
});

//设计单位信息
const searchFields2 = ref({
	socialCode: {
		type: 'input',
		label: '统一社会信用代码',
		placeholder: '请输入统一社会信用代码',
		maxlength: 18,
		showWordLimit: true,
		span: 8,
	},
	designUnit: {
		type: 'input',
		label: '设计单位名称',
		placeholder: '请输入设计单位名称',
		span: 8,
		maxlength: 16,
		showWordLimit: true,
	},
});
//数字化应用信息
const searchFields3 = ref({
	appCode: {
		type: 'input',
		label: '项目编码',
		disabled: false,
		required: true,
		span: 8,
	},
	appName: {
		type: 'input',
		label: '数字化应用名称',
		disabled: false,
		required: true,
		span: 8,
	},
	principalName: {
		type: 'input',
		label: '负责人姓名',
		placeholder: '请输入负责人姓名',
		maxlength: 8,
		showWordLimit: true,
		required: true,
		span: 8,
	},
	principalPhone: {
		type: 'inputPhone',
		label: '负责人电话',
		placeholder: '请输入负责人电话',
		required: true,
		// rules: [
		// 	{ required: true, message: '请输入手机号码', trigger: 'blur' },
		// 	{ pattern: /^1[3456789]\d{9}$/, message: '手机号码格式不正确', trigger: 'blur' },
		// ],
		span: 8,
	},
	projectType: {
		type: 'select',
		label: '应用项目类别',
		required: true,
		options: [],
		span: 8,
	},
	developStatus: {
		type: 'select',
		label: '行业地图（专题地图）开发情况',
		span: 8,
		required: true,
		options: [],
	},
	budgetYear: {
		type: 'date',
		label: '应用预算年度',
		required: true,
		picker: 'year',
		showFormat: 'YYYY',
		span: 8,
	},
	developBeginDateArr: {
		type: 'date',
		picker: 'datetimerange',
		span: 8,
		label: '应用开发时间',
		required: true,
	},
	domain: {
		type: 'input',
		label: '应用领域',
		required: true,
		disabled: false,
		span: 8,
		options: [],
	},
	supervise: {
		type: 'select',
		label: '是否涉及执法监督等相关事项',
		required: true,
		span: 8,
		options: [],
	},
	paper: {
		type: 'select',
		label: '是否提交纸质件',
		required: true,
		options: [],
		span: 8,
	},
	according: {
		type: 'textarea',
		label: '应用申报依据',
		placeholder: '请输入应用申报依据',
		required: true,
		maxlength: 500,
		rows: 3,
		span: 24,
	},
	summarize: {
		type: 'textarea',
		label: '应用概述',
		required: true,
		placeholder: '简述应用包含内容，涉及业务板块、功能模块、业务支撑情况、涉及数据类型、用户量估算、用户群体等相关信息',
		maxlength: 500,
		rows: 3,
		span: 24,
	},
	terminal: {
		type: 'tag',
		label: '应用发布端',
		required: true,
		span: 8,
		options: [],
		change(e) {
			searchFields3.value.zfbIssue.type = e.includes('3') ? 'date' : '';
			searchFields3.value.chatIssue.type = e.includes('4') ? 'date' : '';
			searchFields3.value.webIssue.type = e.includes('5') ? 'date' : '';
			searchFields3.value.pcIssue.type = e.includes('6') ? 'date' : '';
		},
	},
	zfbIssue: {
		type: '',
		label: '支付宝发布时间',
		placeholder: '请选择发布时间',
		span: 8,
		required: true,
	},
	chatIssue: {
		type: '',
		label: '微信发布时间',
		placeholder: '请选择发布时间',
		span: 8,
		required: true,
	},
	webIssue: {
		type: '',
		label: '网页发布时间',
		placeholder: '请选择发布时间',
		span: 8,
		required: true,
	},
	pcIssue: {
		type: '',
		label: 'PC客户端发布时间',
		placeholder: '请选择发布时间',
		span: 8,
		required: true,
	},
	totalBudget: {
		type: 'inputFunny',
		label: '应用总预算',
		span: 8,
		required: true,
	},
	yearBudget: {
		type: 'inputFunny',
		label: '应用年度预算',
		span: 8,
		required: true,
	},
	fundResource: {
		type: 'tag',
		label: '资金来源',
		span: 24,
		required: true,
		options: [],
		change(e) {
			searchFields3.value.centerAmount.type = e.includes('1') ? 'inputFunny' : '';
			searchFields3.value.cityAmount.type = e.includes('2') ? 'inputFunny' : '';
			searchFields3.value.districtAmount.type = e.includes('3') ? 'inputFunny' : '';
			searchFields3.value.deptAmount.type = e.includes('4') ? 'inputFunny' : '';
			searchFields3.value.bankAmount.type = e.includes('5') ? 'inputFunny' : '';
			searchFields3.value.otherFund.type = e.includes('6') ? 'input' : '';
			searchFields3.value.otherAmount.type = e.includes('6') ? 'inputFunny' : '';
		},
	},
	centerAmount: {
		type: '',
		label: '中央财政资金',
		placeholder: '请输入金额',
		required: true,
		span: 12,
	},
	cityAmount: {
		type: '',
		label: '市级财政资金',
		placeholder: '请输入金额',
		required: true,
		span: 12,
	},
	districtAmount: {
		type: '',
		label: '区县财政资金',
		placeholder: '请输入金额',
		required: true,
		span: 12,
	},
	deptAmount: {
		type: '',
		label: '部门自筹资金',
		placeholder: '请输入金额',
		required: true,
		span: 12,
	},
	bankAmount: {
		type: '',
		label: '银行贷款等投资',
		placeholder: '请输入金额',
		required: true,
		span: 12,
	},
	otherFund: {
		type: '',
		label: '其他资金来源名称',
		placeholder: '请输入其他资金来源名称',
		maxlength: 32,
		showWordLimit: true,
		span: 12,
		required: true,
	},
	otherAmount: {
		type: '',
		label: '其他',
		placeholder: '请输入金额',
		required: true,
		span: 12,
	},
});
//数字化应用信息
const searchFields4 = ref({
	netResource: {
		type: 'tag',
		label: '网络资源类型（多选）',
		required: true,
		span: 12,
		options: [],
		change(e) {
			netResource3.value = e.includes('3') ? true : false;
			netResource4.value = e.includes('4') ? true : false;
			netResource5.value = e.includes('5') ? true : false;
			netResource6.value = e.includes('6') ? true : false;
		},
	},
});
//部门专网
const searchFields5 = ref({
	according: {
		type: 'textarea',
		label: '申请依据',
		rows: 3,
		span: 24,
		maxlength: 500,
		placeholder: '提供国家部委有明确要求建设私有云或数字重庆建设领导小组同意的依据',
		required: true,
	},
	budget: {
		type: 'inputFunny',
		label: '预算金额',
		span: 12,
		placeholder: '请输入预算金额',
		required: true,
	},
});
//部门专线
const searchFields6 = ref({
	selfName: {
		type: 'input',
		label: '本端名称',
		maxlength: 16,
		showWordLimit: true,
		span: 12,
		placeholder: '请输入本端名称',
		required: true,
	},
	oppositeName: {
		type: 'input',
		label: '对端名称',
		// rows:3,
		span: 12,
		maxlength: 16,
		showWordLimit: true,
		placeholder: '请输入对端名称',
		required: true,
	},
	according: {
		type: 'textarea',
		label: '申请依据',
		rows: 3,
		span: 24,
		maxlength: 500,
		placeholder: '提供国家部委有明确要求建设私有云或数字重庆建设领导小组同意的依据',
		required: true,
	},
	budget: {
		type: 'inputFunny',
		label: '预算金额',
		span: 12,
		placeholder: '请输入预算金额',
		required: true,
	},
});
//部门专线
const searchFields7 = ref({
	selfName: {
		type: 'input',
		label: '本端名称',
		span: 12,
		maxlength: 16,
		showWordLimit: true,
		placeholder: '请输入本端名称',
		required: true,
	},
	according: {
		type: 'textarea',
		label: '申请依据',
		rows: 3,
		span: 24,
		maxlength: 500,
		placeholder: '提供国家部委有明确要求建设私有云或数字重庆建设领导小组同意的依据',
		required: true,
	},
	budget: {
		type: 'inputFunny',
		label: '预算金额',
		span: 12,
		placeholder: '请输入预算金额',
		required: true,
	},
});
//部门专线
const searchFields8 = ref({
	selfName: {
		type: 'input',
		label: '本端名称',
		maxlength: 16,
		showWordLimit: true,
		span: 12,
		placeholder: '请输入本端名称',
		required: true,
	},
	oppositeName: {
		type: 'input',
		label: '对端名称',
		maxlength: 16,
		showWordLimit: true,
		span: 12,
		placeholder: '请输入对端名称',
		required: true,
	},
	condition: {
		type: 'textarea',
		label: '情况说明',
		rows: 3,
		span: 24,
		maxlength: 500,
		placeholder: '说明电子政务外网需求情况说明',
		required: true,
	},
	budget: {
		type: 'inputFunny',
		label: '预算金额',
		span: 12,
		placeholder: '请输入预算金额',
		required: true,
	},
});
const tabls = computed(() => {});
const tableColumns = computed(() => {
	return {};
});
const tableConfigData = computed({
	get: () => {
		return;
	},
	set: (val) => {},
});
const router = useRouter();
const route = useRoute();
const showDetails = (row: any) => {
	router.push({
		path: '../detail/demandDeclaration',
	});
};
const handleClick = (tab: TabsPaneContext, event: Event) => {};

const afterSubmit = () => {
	mittBus.emit('onCurrentContextmenuClick', Object.assign({}, { contextMenuClickId: 1, ...route }));
	router.push('../digitalLization/index');
};
//submitPass 为成功后的回调函数
const startRef = ref();
const submitPass = () => {
	afterSubmit();
	// mittBus.emit('onCurrentContextmenuClick', Object.assign({}, { contextMenuClickId: 1, ...route }));
};
//申报函数
const declareSubmitList = async (data?: any) => {
	const loading = ElLoading.service({
		lock: true,
		text: '提交中...',
	});
	await declareSubmit(data)
		.then((result) => {
			if (result.ok) {
				//最新的businessKey赋值declareId
				declareId.value = result.data?.businessKey;
				// getByIdAppDeclare(result.data?.businessKey).then((res) => {
				// 	startRef.value.handle({
				// 		flowName: result?.data?.flowName,
				// 		businessKey: result.data?.businessKey,
				// 	});
				// });
				startRef.value.handle({
					flowName: result?.data?.flowName,
					businessKey: result.data?.businessKey,
				});
			} else {
				ElMessage({
					type: 'error',
					message: result.data,
				}); //防止出现其他情况如申报时数据被删除
				// setTimeout(() => {
				// 	afterSubmit();
				// }, 300);
			}
		})
		.finally(() => {
			loading.close();
		});
};
//定义子组件实例
const firstTab = ref();
const secondTab = ref();
const thirdTab = ref();

//保存
const submitValueList = async (str?: string) => {
	isDeclareSubmit.value = str == 'save' ? false : true;
	confirm();
	const netListString = dataList.value?.net?.netResource;
	//触发子组件方法
	firstTab.value.confirm();
	secondTab.value.confirm();
	if (firstTab.value.dataList?.irs?.irsName && firstTab.value.dataList?.irs?.irsCode) {
		// const budgetList = formatTable(JSON.parse(JSON.stringify(TableFormData.value.tableData)), 0);
		const data = {
			id: declareId.value,
			type: chooseType.value,
			base: dataList.value.base,
			net: dataList.value.net,
			irs: firstTab.value.dataList.irs,
			dev: secondTab.value.dataList.dev,
			budget: {
				// budget: formatData(budgetList),
				budget: formatData(JSON.parse(JSON.stringify(TableFormData.value.tableData))),
				total: formDataTotalBudget.value,
			},
			calculate: {
				budget: formatData(JSON.parse(JSON.stringify(TableFormDataCal.value.tableData))),
				total: formDataTotalCalCulate.value,
			},
		};
		switch (str) {
			case 'save':
				declareSaveList(data).then((res) => {
					// setTimeout(() => {
					// 	afterSubmit();
					// }, 300);
				}); //保存

				break;
			default: //申报
				const arr = [
					hyFormRefRespons1.value?.check(),
					hyFormRefRespons2.value?.check(),
					hyFormRefRespons3.value?.check(),
					hyFormRefRespons4.value?.check(),
				];
				if ((netListString.search('3') != -1) == true) {
					arr.push(hyFormRefRespons5.value?.check());
				}
				if ((netListString.search('4') != -1) == true) {
					arr.push(hyFormRefRespons6.value?.check());
				}
				if ((netListString.search('5') != -1) == true) {
					arr.push(hyFormRefRespons7.value?.check());
				}
				if ((netListString.search('6') != -1) == true) {
					arr.push(hyFormRefRespons8.value?.check());
				}
				const checked = await Promise.all(arr);
				if (checked.every((item) => Boolean(item))) {
					declareSubmitList(data);
					// ElMessageBox.confirm(
					// 	'确认提交申报？', //提示内容
					// 	'操作确认',
					// 	{
					// 		confirmButtonText: '确认',
					// 		cancelButtonText: '取消',
					// 		type: 'warning',
					// 	}
					// ).then(() => {
					// 	declareSubmitList(data); //申报
					// });
					// declareSubmitList(data).then((res) => {
					// 	startRef.value.handle({
					// 		flowCode: flowCode.EXPERT,
					// 		businessKey: res?.businessKey,
					// 		paramMap: { businessKey: res.businessKey },
					// 	});
					// });
				}
				break;
		}
	} else {
		ElMessage.error('请先选择关联IRS应用！');
	}
};

const setAppCodeName = () => {
	searchDefault3.value.appCode = appCode.value; //编号
	searchFields3.value.appCode.disabled = true;
	searchDefault3.value.appName = threeListName.value; //应用名称
	searchFields3.value.appName.disabled = true;
};
const declareByAppCode = async () => {
	editPageAdd.value = true;
	const loading = ElLoading.service({
		lock: true,
		text: '获取数据中...',
	});
	await getByIdAppDeclare(declareId.value)
		.then((res) => {
			if (res.data) {
				if (res.data.budget && res.data.budget.budget) {
					tableData.value = formatDataList(res.data.budget.budget); //转换资金明细数据结构
				}
				if (res.data.calculate && res.data.calculate.budget) {
					tableDataThere.value = formatDataList(res.data.calculate.budget); //转换资金明细数据结构
				}
				appCode.value = res.data.base.appCode;
				chooseType.value = res.data.type;
				if (res.data.irs) {
					firstTabList.value = res.data.irs;
					secondTabList.value = res.data.dev;
				}
				searchFields1.value.reportDetail.type = res.data.base.report == '1' ? 'textarea' : '';
				searchFields3.value.appCode.disabled = true;
				searchFields3.value.appName.disabled = true;
				searchFields3.value.domain.disabled = true;
				const NO1 = {
					responsibleDept: res.data.base.responsibleDept,
					budgetUnit: res.data.base.budgetUnit,
					leadDept: res.data.base.leadDept,
					report: isNull(res.data.base?.report),
					reportDetail: res.data.base.reportDetail,
				};
				const NO2 = {
					designUnit: isNull(res.data.base?.designUnit), //设计单位名称
					socialCode: isNull(res.data.base?.socialCode), //统一社会信用代码
				};
				const terminal = (res.data.base.terminal && res.data.base.terminal.split(',')) || [];
				const fundResource = (res.data.base.fundResource && res.data.base.fundResource.split(',')) || [];
				const NO3 = {
					appCode: res.data.base?.appCode,
					appName: res.data.base?.appName,
					principalName: res.data.base?.principalName,
					principalPhone: res.data.base?.principalPhone - 0,
					projectType: isNull(res.data.base?.projectType),
					developStatus: isNull(res.data.base?.developStatus),
					budgetYear: res.data.base?.budgetYear,
					developBeginDateArr: res.data.base.developBeginDate
						? [res.data.base.developBeginDate + '00:00:00', res.data.base.developEndDate + '00:00:00']
						: [],
					domain: res.data.base?.domain,
					according: res.data.base?.according,
					summarize: res.data.base?.summarize,
					totalBudget: res.data.base?.totalBudget,
					yearBudget: res.data.base?.yearBudget,
					otherFund: res.data.base?.otherFund,
					centerAmount: res.data.base?.centerAmount,
					cityAmount: res.data.base?.cityAmount,
					districtAmount: res.data.base?.districtAmount,
					deptAmount: res.data.base?.deptAmount,
					bankAmount: res.data.base?.bankAmount,
					otherAmount: res.data.base?.otherAmount,
					supervise: isNull(res.data.base?.supervise),
					paper: isNull(res.data.base?.paper),
					terminal: terminal,
					fundResource: fundResource,
					zfbIssue: res.data.base?.zfbIssue,
					chatIssue: res.data.base?.chatIssue,
					webIssue: res.data.base?.webIssue,
					pcIssue: res.data.base?.pcIssue,
				};
				if (terminal && terminal.length) {
					searchFields3.value.zfbIssue.type = terminal.includes('3') ? 'date' : '';
					searchFields3.value.chatIssue.type = terminal.includes('4') ? 'date' : '';
					searchFields3.value.webIssue.type = terminal.includes('5') ? 'date' : '';
					searchFields3.value.pcIssue.type = terminal.includes('6') ? 'date' : '';
				}
				if (fundResource && fundResource.length) {
					searchFields3.value.centerAmount.type = fundResource.includes('1') ? 'inputFunny' : '';
					searchFields3.value.cityAmount.type = fundResource.includes('2') ? 'inputFunny' : '';
					searchFields3.value.districtAmount.type = fundResource.includes('3') ? 'inputFunny' : '';
					searchFields3.value.deptAmount.type = fundResource.includes('4') ? 'inputFunny' : '';
					searchFields3.value.bankAmount.type = fundResource.includes('5') ? 'inputFunny' : '';
					searchFields3.value.otherFund.type = fundResource.includes('6') ? 'input' : '';
					searchFields3.value.otherAmount.type = fundResource.includes('6') ? 'inputFunny' : '';
				}
				const netResource = (res.data.net && res.data.net.netResource && res.data.net.netResource.split(',')) || [];
				const NO4 = {
					netResource: netResource,
				};
				if (netResource && netResource.length) {
					netResource3.value = netResource.includes('3') ? true : false;
					netResource4.value = netResource.includes('4') ? true : false;
					netResource5.value = netResource.includes('5') ? true : false;
					netResource6.value = netResource.includes('6') ? true : false;
				}
				//部门专线
				const searchFieldsZhuanZian =
					res.data.net.netList.find((item) => {
						return item.type == '4';
					}) || {};
				decCardList2.value = searchFieldsZhuanZian?.files || [];
				//部门专网
				const searchFieldsZhuanWang =
					res.data.net.netList.find((item) => {
						return item.type == '3';
					}) || {};
				decCardList1.value = searchFieldsZhuanWang?.files || [];
				//互联网专线
				const searchFieldsHuLian =
					res.data.net.netList.find((item) => {
						return item.type == '5';
					}) || {};
				decCardList3.value = searchFieldsHuLian?.files || [];
				//电子政务外网部门接入网
				const searchFieldsDianZi =
					res.data.net.netList.find((item) => {
						return item.type == '6';
					}) || {};
				decCardList4.value = searchFieldsDianZi?.files || [];
				const NO5 = {
					selfName: searchFieldsZhuanZian?.selfName,
					oppositeName: searchFieldsZhuanZian?.oppositeName,
					according: searchFieldsZhuanZian?.according,
					budget: searchFieldsZhuanZian?.budget,
				};
				const NO6 = {
					budget: searchFieldsZhuanWang?.budget,
					according: searchFieldsZhuanWang?.according,
				};
				const NO7 = {
					budget: searchFieldsHuLian?.budget,
					according: searchFieldsHuLian?.according,
					selfName: searchFieldsHuLian?.selfName,
				};
				const NO8 = {
					selfName: searchFieldsDianZi?.selfName,
					oppositeName: searchFieldsDianZi?.oppositeName,
					condition: searchFieldsDianZi?.condition,
					budget: searchFieldsDianZi?.budget,
				};
				if (res.data && res.data.net) {
					const net = res.data.net;
					decCardList5.value = net.matter || [];
					decCardList6.value = net.fundReport || [];
					imgList.value = {
						businessImgFiles: net.businessImg ? [net.businessImg] : [],
						systemImgFiles: net.systemImg ? [net.systemImg] : [],
						dataImgFiles: net.dataImg ? [net.dataImg] : [],
						netImgFiles: net.netImg ? [net.netImg] : [],
					};
				}
				searchDefault1.value = { ...NO1 };
				searchDefault2.value = { ...NO2 };
				searchDefault3.value = { ...NO3 };
				searchDefault4.value = { ...NO4 };
				searchDefault5.value = { ...NO5 };
				searchDefault6.value = { ...NO6 };
				searchDefault7.value = { ...NO7 };
				searchDefault8.value = { ...NO8 };
				if (res.data.report) {
					searchFields1.value.reportDetail.type = 'textarea';
				}
			}
		})
		.finally(() => {
			loading.close();
		});
};
onMounted(() => {
	const { yes_no_type, app_project_type, industry_map, supervise_type, terminal, fund_resource, net_nesource } = useDict(
		'yes_no_type',
		'app_project_type',
		'industry_map',
		'supervise_type',
		'terminal',
		'fund_resource',
		'net_nesource'
	);
	searchFields1.value.report.options = yes_no_type;
	searchFields3.value.paper.options = yes_no_type;
	searchFields3.value.projectType.options = app_project_type;
	searchFields3.value.developStatus.options = industry_map;
	searchFields3.value.supervise.options = supervise_type;
	searchFields3.value.terminal.options = terminal;
	searchFields3.value.fundResource.options = fund_resource;
	searchFields4.value.netResource.options = net_nesource;

	const routerData = router.currentRoute.value.query;
	chooseType.value = routerData.chooseType;
	declareId.value = routerData.declareId;
	appCode.value = routerData.appCode;
	threeListName.value = routerData.threeListName;
	belongDomain.value = routerData.belongDomain; //应用领域对应value
	belongDomainName.value = routerData.belongDomainName; //应用领域
	searchDefault1.value.responsibleDept = routerData.liabilityDepartment;
	searchDefault1.value.leadDept = routerData.teamLeaderUnitName;
	//editPage标记为编辑
	if (routerData.editPage) {
		declareByAppCode();
	}
	//赋值关联应用
	if (routerData.setAppCode) {
		setAppCodeName();
	}
	if (routerData.belongDomain) {
		const NO1 = {
			appCode: routerData.appCode,
			appName: routerData.threeListName,
			domain: routerData.belongDomainName,
		};
		searchDefault3.value = {
			...NO1,
		};
		searchFields3.value.domain.disabled = true;
	}
});
</script>
<style scoped lang="scss">
.HyCard {
	margin-top: 10px;
}
.uploadDiv {
	width: 100%;
	span {
		display: inline-block;
		margin: 10px 0;
	}
}
.span-require {
	color: red;
}
.uploadDivNext {
	margin-top: 20px;
}
.imglist {
	width: 100%;
	display: flex;
	justify-content: space-between;
	.listitem {
		width: 21%;
	}
}
</style>
